package com.finer.service.impl;

import com.finer.dao.FinerSaleRequestDao;
import com.finer.entity.sell.FinerSaleRequest;
import com.finer.service.FinerSaleRequestService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 销售申请表(FinerSaleRequest)表服务实现类
 *
 * @author makejava
 * @since 2024-10-21 10:20:39
 */
@Service("finerSaleRequestService")
public class FinerSaleRequestServiceImpl implements FinerSaleRequestService {
    @Resource
    private FinerSaleRequestDao finerSaleRequestDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public FinerSaleRequest queryById(Integer id) {
        return this.finerSaleRequestDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param finerSaleRequest 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<FinerSaleRequest> queryByPage(FinerSaleRequest finerSaleRequest, PageRequest pageRequest) {
        long total = this.finerSaleRequestDao.count(finerSaleRequest);
        return new PageImpl<>(this.finerSaleRequestDao.queryAllByLimit(finerSaleRequest, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param finerSaleRequest 实例对象
     * @return 实例对象
     */
    @Override
    public FinerSaleRequest insert(FinerSaleRequest finerSaleRequest) {
        this.finerSaleRequestDao.insert(finerSaleRequest);
        return finerSaleRequest;
    }

    /**
     * 修改数据
     *
     * @param finerSaleRequest 实例对象
     * @return 实例对象
     */
    @Override
    public FinerSaleRequest update(FinerSaleRequest finerSaleRequest) {
        this.finerSaleRequestDao.update(finerSaleRequest);
        return this.queryById(finerSaleRequest.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.finerSaleRequestDao.deleteById(id) > 0;
    }
}
